<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>

</style>

<body>
    <img id="on" src="./img/20210420123914108.gif" alt="">
    <button class="kai">开</button><button class="guan">关</button>
</body>
<script>
    var date = [
        {
            img: './img/20210420123914108.gif',
            img1: './img/20210420123919142.gif',
        }
    ]
    var img = document.getElementById('on');
    var kai = document.querySelector('.kai');
    var guan = document.querySelector('.guan');

    function sum() {
        kai.onclick = function () {
            on.src = `${date[0].img1}`;
        }
        guan.onclick = function () {
            on.src = `${date[0].img}`;
        }
    }
    sum();

    function fn() {
        var flag = 0;
        on.onclick = function () {
            if (flag) {
                on.src = `${date[0].img}`;
                flag = 0;
            } else {
                on.src = `${date[0].img1}`;
                flag = 1;
            }
        }
    }
    fn();
</script>

</html>